<template>
  <div class="head-container">
    <!-- 搜索 -->
    <div v-show="sup_this.searchToggle">
      <el-select v-model="paramBean.otherStateList" size="mini" style="width: 260px;" multiple clearable placeholder="请选择状态">
        <el-option v-for="item in dicts.bus_other_state" :key="item.id" :label="item.dictName" :value="item.dictCode"/>
      </el-select>
      <el-input v-model="paramBean.busCpyName" clearable placeholder="输入供应商搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-input v-model="paramBean.sysGenCode" clearable placeholder="输入系统编号搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="sup_this.toQuery">搜索</el-button>
      <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="sup_this.resetQuery()">重置</el-button>
    </div>
    <div class="crud-opts">
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','PURCHASE_PO_ALL','PURCHASE_PO_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-s-order"
        @click="toPurchasePo">采购订单</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','PURCHASE_PO_ALL','PURCHASE_PO_CREATE']"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-finished"
        @click="doManualProcess">标记已处理</el-button>
      <DataGridOpts :sup_this="sup_this" @refreshClick="refreshClick" @searchClick="searchClick" />
    </div>
    <po-form ref="poForm" :sup_this="sup_this" />
  </div>
</template>

<script>
import order from '@/api/business/Order'
import poForm from '@/views/purchase/po/module/form'

export default {
  components: { poForm },
  dictTypes: ['bus_other_state'],
  props: {
    paramBean: {
      type: Object,
      required: true
    },
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      deleteLoading: false,
      submitLoading: false,
      destoryLoading: false
    }
  },
  methods: {
    refreshClick() {
      this.sup_this.init()
    },
    searchClick() {
      this.sup_this.toggleSearch()
    },
    beforeCreate() {
    },
    doManualProcess() {
      const _this = this.sup_this
      _this.doManualProcessOtherState(order.manualProcessOtherStateUrl(), this)
    },
    toPurchasePo() {
      const _this = this.sup_this
      const busRelList = []
      let cpyKey = null
      let cpyDiffFlag = false
      _this.selectedGridRows.forEach(row => {
        if ((cpyKey && cpyKey !== row.sysOwnerCpy) || row.selfState !== '10') {
          cpyDiffFlag = true
          return
        }
        cpyKey = row.sysOwnerCpy
        busRelList.push({ fromBusModule: row.busModule, fromBusClass: row.busClass, fromCode: row.sysGenCode, fromId: row.id })
      })
      if (cpyDiffFlag) {
        this.$message({
          message: '请选择相同供应商',
          type: 'warning'
        })
        return
      }
      if (busRelList.length === 0) {
        this.$message({
          message: '请选择记录',
          type: 'warning'
        })
        return
      }
      const _thisform = this.$refs.poForm
      _thisform.initDataOfBefore()
      _thisform.addDataFromOrder(busRelList)
    }
  }
}
</script>
